﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.HtmlControls;
using cnFederal.FaCode;

namespace cnFederal.Fa_Forms
{
    public partial class SelectedContent : System.Web.UI.Page
    {
        public SelectedContent()
        {
           
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            CnfImages.Load();
            int id = int.Parse(Request.QueryString["Id"]);
            LoadObject(id);
            //fbLikeButton.Url = Request.Url.AbsoluteUri;
            //fbLikeButton.ShowFaces = true;
            
        
        }

        public int MainContentHeight
        {
            get;
            set;
        }
        FaPost _post;
        private void LoadObject(int id)
        {
          
          FaPost post=  FaPosts.GetFaPostById(id);
          _post = post;
            if (post != null)
            {
                this.MainContentHeight = post.MainContent.Length / 10;
                TextBoxIngress.Text = post.Header;
                TextBoxTitle.Text = post.Title + Environment.NewLine +
                    " <br /> Date:  "+post.DateStartPublish.ToShortDateString() + Environment.NewLine;

                string temp = post.MainContent.Replace("\n", "<br>");
                TextBoxContent.Text = temp;
                Image1.ImageUrl =  post.ImageUrl;
                this.ImageUrl = post.ImageUrl;
              
                SetFacebookMeta(post.Title, post.ImageUrl,post.Header);
                AddStyle(post.NewsType);
             
            }
          
        }

        public void AddStyle(int postTypeId)
        {
            List<string[]> styleArray = new List<string[]>();
            //Ingress and Header style
            if (postTypeId == 10)
            {
                styleArray.Add(new string[] { "direction", "ltr" });
                styleArray.Add(new string[] { "text-align", "left" });
            }
            else
            {
                styleArray.Add(new string[] { "direction", "rtl" });
                styleArray.Add(new string[] { "text-align", "right" });
            }
            styleArray.Add(new string[] { "overflow", "hidden" });
           
            styleArray.Add(new string[] { "display", "inline" });
            styleArray.Add(new string[] { "color", "black" });
            styleArray.Add(new string[] { "font-weight", "400" });
            styleArray.Add(new string[] { "font-size", "16px" });
            styleArray.Add(new string[] { "font-family", "'ZAR___SF'" });
            CnfiFunctions.AddStyleToControl(TextBoxIngress, styleArray);
            CnfiFunctions.AddStyleToControl(TextBoxTitle, styleArray);
            //Content style
            styleArray.RemoveAt(6);
            styleArray.Add(new string[] { "font-size", "14px" });
            styleArray.Add(new string[] { "font-weight", "200" });
            styleArray.Add(new string[] { "font-family", "'ZAR___SF'" });
            CnfiFunctions.AddStyleToControl(TextBoxContent, styleArray);
            styleArray.Clear();
            //Table style
            styleArray.Add(new string[] { "height", "inherit" });
            styleArray.Add(new string[] { "vertical-align", "top" });
            styleArray.Add(new string[] { "border", "0" });
            styleArray.Add(new string[] { "width", "100%" });
            styleArray.Add(new string[] { "font-size", "small" });
            if (postTypeId != 10)
            {
                styleArray.Add(new string[] { "text-align", "right" });
                styleArray.Add(new string[] { "font-family", "'ZAR___SF'" });
            }
            else
            {
                styleArray.Add(new string[] { "text-align", "left" });
                styleArray.Add(new string[] { "font-family", "'Times New Roman'" });
            }
            
            CnfiFunctions.AddStyleToControl(tableContent, styleArray);
            //Image style
            if (postTypeId != 10)
            Image1.ImageAlign = ImageAlign.Left;
            else
                Image1.ImageAlign = ImageAlign.Right;
            
           
        }
        public string NewTitleAndHeaderFarsiStyle
        {
            get
            {
                string st = @"overflow:hidden;
 direction:rtl;
  text-align:right; 
  display:inline; 
  color:black; 
  font-weight:600;
   font-size:small;";
                return st;
            }
        }

        public string GetCssClass
        {
            get
            {
                string cssclass = "newsTitleAndHeaderFarsi";
                if (_post != null)
                {
                    if (_post.NewsType == 10)
                    {
                        cssclass = "newsTitleAndHeaderLantin";
                    }
                }
                return cssclass;
            }
        }
        public void SetFacebookMeta(string title, string imageUrl, string description)
        {
            HtmlMeta tag = new HtmlMeta();
            tag.Attributes.Add("property", "og:title");
            tag.Content = title;
            Page.Header.Controls.Add(tag);
            HtmlMeta imgUrl = new HtmlMeta();
            imgUrl.Attributes.Add("property", "og:image");
            imgUrl.Content = imageUrl;
            Page.Header.Controls.Add(imgUrl);

            HtmlMeta des = new HtmlMeta();
            des.Attributes.Add("property", "og:description");
            des.Content = description;
            Page.Header.Controls.Add(des);
        }
        public string ImageUrl
        {

            get;
            set;
        }
        public string GetAbsolutUri()
        {
           return HttpContext.Current.Request.Url.AbsoluteUri;
        }
      
        public string GetUrl()
        {
            string URL = HttpContext.Current.Request.Url.AbsoluteUri;
            string g = @"https://plus.google.com/share?url={" +URL+"}";
         string test =   @"javascript:window.open("+g +",'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;";
            return test;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            GetUrl();
        }

    }
}